package com.mk.settlement.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mk.settlement.common.Page;
import com.mk.settlement.mappers.SettlementOrderMapper;
import com.mk.settlement.model.SettlementOrder;
import com.mk.settlement.service.StatisticaOrderService;

/**
 * 订单纬度统计展示service实现类
 * @author futao
 *
 */
@Service
public class StatisticaOrderServiceImpl implements StatisticaOrderService {
	
	@Autowired
	private SettlementOrderMapper soMapper;
	
	public Page findData(SettlementOrder sorder,Page page){
		List<SettlementOrder> result=soMapper.findStatisticaOrderList(sorder.getOrderId(),
				sorder.getSettlementTargetName(), sorder.getSettlementCategory(),
				page.getBeginTime(),page.getEndTime(),
				page.getStart(), page.getPageSize(), 
				page.getCurrentPage(),
				page.getOrderby());
		int count=soMapper.selectStatisticaOrderCount(sorder.getOrderId(),
				sorder.getSettlementTargetName(), sorder.getSettlementCategory(),
				page.getBeginTime(),page.getEndTime());
		page.setResult(result);
		page.setTotalRecord( count );
	    page.setTotalPage(page.getTotalPage());
		return page;
	}
	
	@Override
	public int editSettlementSum(Long id,  BigDecimal settlementSum) {
		if(id!=null && id > 0 && settlementSum!=null ){
			 return soMapper.updateSettlementSum(id, settlementSum);
		} 
		return 0;
	}
	
 
	@Override   //导出用的查询
	public List<String[]> findExportData(int titileSize,SettlementOrder sorder,Page page){
		List<String[]> list=new ArrayList<>();
		List<SettlementOrder> result=soMapper.findStatisticaOrderList(sorder.getOrderId(),
				sorder.getSettlementTargetName(), sorder.getSettlementCategory(),
				page.getBeginTime(),page.getEndTime(),
				page.getStart(), page.getPageSize(),
				page.getCurrentPage(),
				page.getOrderby());
		String str[]=null;
		for (SettlementOrder so : result) {
			str=new String[titileSize];
			str[0]=so.getOrderId()+"";
			str[1]=so.getOriginalSum()+"";
			str[2]=so.getSettlementSum()+"";
			str[3]=so.getStrFeeType();
			str[4]=so.getStrSettlementCategory();
			str[5]=so.getStrSettlementType();
			str[6]=so.getStrSettlementState();
			str[7]=so.getSettlementTargetName();
			str[8]=so.getStrCreateTime();
			str[9]=so.getStrSettlementTime();
			
			list.add(str);
		}
		return  list;
	}

	
}